
<!DOCTYPE HTML>
<html lang="" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>moment 和date-fns · GitBook</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        
        
        
    
    <link rel="stylesheet" href="../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="node.JS中配置http-server.html" />
    
    
    <link rel="prev" href="less传参问题：在url中插入变量今天在需要用less给url传递参数时遇到了小问题，一番搜索后有了下述解决方法.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="Type to search" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../">
            
                <a href="../">
            
                    
                    Introduction
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="../cmd命令.html">
            
                <a href="../cmd命令.html">
            
                    
                    cmd命令
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="Array.prototype.slice.call.html">
            
                <a href="Array.prototype.slice.call.html">
            
                    
                    Array.prototype.slice.call解析
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="async 函数.html">
            
                <a href="async 函数.html">
            
                    
                    async 函数
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="callback&&callback如果存在回调函数就执行.html">
            
                <a href="callback&&callback如果存在回调函数就执行.html">
            
                    
                    callback&&callback() 如果存在回调函数就执行！
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6" data-path="CSS3 nth-child使用注意.html">
            
                <a href="CSS3 nth-child使用注意.html">
            
                    
                    CSS3 nth-child(n)使用注意
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7" data-path="css3的 -webkit-min-device-pixel-ratio属性 解决高清的适配.html">
            
                <a href="css3的 -webkit-min-device-pixel-ratio属性 解决高清的适配.html">
            
                    
                    css3的 -webkit-min-device-pixel-ratio属性 解决高清的适配
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8" data-path="CSS文本超出自动缩小字体.html">
            
                <a href="CSS文本超出自动缩小字体.html">
            
                    
                    CSS文本超出自动缩小字体
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9" data-path="element-ui默认样式修改.html">
            
                <a href="element-ui默认样式修改.html">
            
                    
                    element-ui默认样式修改
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10" data-path="JavaScript setInterval函数详解.html">
            
                <a href="JavaScript setInterval函数详解.html">
            
                    
                    JavaScript setInterval() 函数详解
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11" data-path="JavaScript概念之screenclientoffsetscrollinneravail的widthleft.html">
            
                <a href="JavaScript概念之screenclientoffsetscrollinneravail的widthleft.html">
            
                    
                    JavaScript概念之screenclientoffsetscrollinneravail的widthleft
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12" data-path="js获取星期几.html">
            
                <a href="js获取星期几.html">
            
                    
                    js获取星期几
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.13" data-path="js监听滚动条事件和获取浏览器及屏幕高度和宽度等信息的方法.html">
            
                <a href="js监听滚动条事件和获取浏览器及屏幕高度和宽度等信息的方法.html">
            
                    
                    js监听滚动条事件和获取浏览器及屏幕高度和宽度等信息的方法
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.14" data-path="js时间戳与日期格式之间相互转换.html">
            
                <a href="js时间戳与日期格式之间相互转换.html">
            
                    
                    js时间戳与日期格式之间相互转换
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.15" data-path="JS数组reduce方法详解及高级技巧.html">
            
                <a href="JS数组reduce方法详解及高级技巧.html">
            
                    
                    JS数组reduce()方法详解及高级技巧
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.16" data-path="js中获取时间new Date详细介绍.html">
            
                <a href="js中获取时间new Date详细介绍.html">
            
                    
                    js中获取时间new Date()详细介绍
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.17" data-path="less传参问题：在url中插入变量今天在需要用less给url传递参数时遇到了小问题，一番搜索后有了下述解决方法.html">
            
                <a href="less传参问题：在url中插入变量今天在需要用less给url传递参数时遇到了小问题，一番搜索后有了下述解决方法.html">
            
                    
                    less传参问题：在url中插入变量今天在需要用less给url传递参数时遇到了小问题，一番搜索后有了下述解决方法
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="1.18" data-path="moment 和date-fns.html">
            
                <a href="moment 和date-fns.html">
            
                    
                    moment 和date-fns
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.19" data-path="node.JS中配置http-server.html">
            
                <a href="node.JS中配置http-server.html">
            
                    
                    node.JS中配置http-server
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.20" data-path="Object.keys详解.html">
            
                <a href="Object.keys详解.html">
            
                    
                    Object.keys详解
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.21" data-path="router-link各种属性解释.html">
            
                <a href="router-link各种属性解释.html">
            
                    
                    router-link各种属性解释
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.22" data-path="stylus使用介绍.html">
            
                <a href="stylus使用介绍.html">
            
                    
                    stylus使用介绍
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.23" data-path="TypeError Cannot read property 'compilation' of undefined.html">
            
                <a href="TypeError Cannot read property 'compilation' of undefined.html">
            
                    
                    TypeError Cannot read property 'compilation' of undefined
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.24" data-path="Vue  keep-alive.html">
            
                <a href="Vue  keep-alive.html">
            
                    
                    Vue  keep-alive
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.25" data-path="Vue - 过渡与动画transition.html">
            
                <a href="Vue - 过渡与动画transition.html">
            
                    
                    Vue - 过渡与动画transition
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.26" data-path="vue-axios使用方法.html">
            
                <a href="vue-axios使用方法.html">
            
                    
                    vue-axios使用方法
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.27" data-path="vue-calendar-component.html">
            
                <a href="vue-calendar-component.html">
            
                    
                    vue-calendar-component
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.28" data-path="vue-infinite-loading.html">
            
                <a href="vue-infinite-loading.html">
            
                    
                    vue-infinite-loading
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.29" data-path="vue报错There are multiple modules with names that only differ in casing.html">
            
                <a href="vue报错There are multiple modules with names that only differ in casing.html">
            
                    
                    vue报错There are multiple modules with names that only differ in casing
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.30" data-path="Vue中注意target和currentTarget的使用.html">
            
                <a href="Vue中注意target和currentTarget的使用.html">
            
                    
                    Vue中注意target和currentTarget的使用
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.31" data-path="关于给javascript对象添加、删除、修改对象的属性.html">
            
                <a href="关于给javascript对象添加、删除、修改对象的属性.html">
            
                    
                    关于给javascript对象添加、删除、修改对象的属性
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.32" data-path="获取当前地址坐标.html">
            
                <a href="获取当前地址坐标.html">
            
                    
                    获取当前地址坐标
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.33" data-path="解决ajax跨域问题【5种解决方案】.html">
            
                <a href="解决ajax跨域问题【5种解决方案】.html">
            
                    
                    解决ajax跨域问题【5种解决方案】
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.34" data-path="解决vue-cli webpack打包后加载资源的路径问题.html">
            
                <a href="解决vue-cli webpack打包后加载资源的路径问题.html">
            
                    
                    解决vue-cli webpack打包后加载资源的路径问题
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.35" data-path="时间格式转换：201971转换为2019-7-1.html">
            
                <a href="时间格式转换：201971转换为2019-7-1.html">
            
                    
                    时间格式转换：201971转换为2019-7-1
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.36" data-path="数据库密码改了.html">
            
                <a href="数据库密码改了.html">
            
                    
                    数据库密码改了
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.37" data-path="语法getBoundingClientRect.html">
            
                <a href="语法getBoundingClientRect.html">
            
                    
                    语法getBoundingClientRect()
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.38" data-path="在js中使用length报错Error in renderTypeErrorcannot read property bgImg of null.html">
            
                <a href="在js中使用length报错Error in renderTypeErrorcannot read property bgImg of null.html">
            
                    
                    在js中使用length报错Error in renderTypeErrorcannot read property bgImg of null
            
                </a>
            

            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            Published with GitBook
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href=".." >moment 和date-fns</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h1 id="date-fns">date-fns</h1>
<p>date-fns&#x8F83;moment&#x76F8;&#x6BD4;&#xFF0C;&#x66F4;&#x4E3A;&#x8F7B;&#x91CF;&#x5316;&#xFF0C;&#x5728;&#x5B9E;&#x9645;&#x5F00;&#x53D1;&#x4E2D;&#x63A8;&#x8350;&#x4F7F;&#x7528;date-fns&#x3002;&#x4E0B;&#x9762;&#x8FD8;&#x662F;&#x4ECB;&#x7ECD;&#x5B83;&#x7684;&#x4F7F;&#x7528;&#x65B9;&#x5F0F;&#xFF1A;</p>
<p>&#x4E00;&#x3001;&#x5B89;&#x88C5;moment.js</p>
<p>npm install --save date-fns</p>
<p>&#x4E8C;&#x3001;&#x81EA;&#x5B9A;&#x4E49;&#x8FC7;&#x6EE4;&#x5668;filter.js&#x6587;&#x4EF6;</p>
<pre><code>//filter.js
</code></pre><p>&#x200B;<br>    import Vue from &apos;vue&apos;
    import format from &apos;date-fns/format&apos;</p>
<pre><code>//&#x81EA;&#x5B9A;&#x4E49;&#x8FC7;&#x6EE4;&#x5668;
Vue.filter(&apos;date-format&apos;,function(value,formatStr=&apos;YYYY-MM-DD HH:mm:ss&apos;){
    return format(value,formatStr)
})
</code></pre><p>&#x4E09;&#x3001;&#x5728;&#x5165;&#x53E3;js&#x4E2D;&#x52A0;&#x8F7D;</p>
<p>import &apos;./filter.js&apos;//&#x52A0;&#x8F7D;&#x8FC7;&#x6EE4;&#x5668;</p>
<p>&#x56DB;&#x3001;&#x5728;&#x9875;&#x9762;&#x4E2D;&#x4F7F;&#x7528;</p>
<h2 id="nan"><div class="time">NaN</div></h2>
<p>&#x4F5C;&#x8005;&#xFF1A;&#x627F;&#x8499;&#x65F6;&#x5149;&#x4E0D;&#x5F03;1769203735 
&#x6765;&#x6E90;&#xFF1A;CSDN 
&#x539F;&#x6587;&#xFF1A;<a href="https://blog.csdn.net/qq_36742720/article/details/83719615" target="_blank">https://blog.csdn.net/qq_36742720/article/details/83719615</a> 
&#x7248;&#x6743;&#x58F0;&#x660E;&#xFF1A;&#x672C;&#x6587;&#x4E3A;&#x535A;&#x4E3B;&#x539F;&#x521B;&#x6587;&#x7AE0;&#xFF0C;&#x8F6C;&#x8F7D;&#x8BF7;&#x9644;&#x4E0A;&#x535A;&#x6587;&#x94FE;&#x63A5;&#xFF01;</p>
<h1 id="moment">moment</h1>
<p>&#x603B;&#x7ED3;&#x4E00;&#x4E2A;&#x975E;&#x5E38;&#x5B9E;&#x7528;&#x7684;&#x65E5;&#x671F;&#x5DE5;&#x5177;&#x7C7B;moment.js&#xFF0C;&#x65E5;&#x671F;&#x83B7;&#x53D6;&#xFF0C;&#x683C;&#x5F0F;&#x5316;&#x7B49;&#x3002;
 &#x90FD;&#x662F;&#x4EE5;&#x524D;&#x5DE5;&#x4F5C;&#x4E2D;&#x9047;&#x5230;&#x7684;&#xFF0C;&#x6211;&#x4F1A;&#x5728;&#x4F7F;&#x7528;&#x5DE5;&#x5177;&#x7C7B;&#x7684;&#x65F6;&#x5019;&#x65B0;&#x5EFA;&#x4E00;&#x4E2A;js&#xFF0C;&#x5DE5;&#x4F5C;&#x4E2D;&#x9047;&#x5230;&#x8981;&#x663E;&#x793A;&#x4EC0;&#x4E48;&#x90FD;&#x5728;&#x8FD9;&#x4E2A;&#x6587;&#x4EF6;&#x91CC;&#x5C1D;&#x8BD5;&#xFF0C;&#x6240;&#x4EE5;&#x8FD9;&#x4E2A;&#x987A;&#x5E8F;&#x662F;&#x6211;&#x5DE5;&#x4F5C;&#x4E2D;&#x9047;&#x5230;&#x7136;&#x540E;&#x5728;js&#x6587;&#x4EF6;&#x4E2D;&#x5C1D;&#x8BD5;&#x7684;&#x987A;&#x5E8F;&#xFF0C;&#x53EF;&#x80FD;&#x987A;&#x5E8F;&#x7A0D;&#x5FAE;&#x4E71;&#x4E00;&#x4E9B;&#xFF0C;&#x4F46;&#x662F;&#x5927;&#x81F4;&#x6CA1;&#x6709;&#x4EC0;&#x4E48;&#x95EE;&#x9898;&#x3002;</p>
<h2 id="&#x5F15;&#x5165;moment">&#x5F15;&#x5165;moment</h2>
<pre><code>//require &#x65B9;&#x5F0F;
var moment=require(&apos;moment&apos;);

//import &#x65B9;&#x5F0F;
import moment from &apos;moment&apos;;
</code></pre><h2 id="&#x8BBE;&#x5B9A;moment&#x533A;&#x57DF;&#x4E3A;&#x4E2D;&#x56FD;">&#x8BBE;&#x5B9A;moment&#x533A;&#x57DF;&#x4E3A;&#x4E2D;&#x56FD;</h2>
<pre><code>//require &#x65B9;&#x5F0F;
require(&apos;moment/locale/zh-cn&apos;)
moment.locale(&apos;zh-cn&apos;); 
//import &#x65B9;&#x5F0F;
import &apos;moment/locale/zh-cn&apos;
moment.locale(&apos;zh-cn&apos;);
</code></pre><h2 id="&#x683C;&#x5F0F;&#x5316;&#x65F6;&#x95F4;&#x7C7B;&#x578B;">&#x683C;&#x5F0F;&#x5316;&#x65F6;&#x95F4;&#x7C7B;&#x578B;</h2>
<p>1.&#x53D6;&#x5F53;&#x5929;&#x65F6;&#x95F4;&#xFF0C;&#x4EE5;YYYY&#x5E74;MM&#x6708;DD&#x65E5;&#x5F62;&#x5F0F;&#x663E;&#x793A;</p>
<pre><code>var now=moment().format(&quot;YYYY&#x5E74;MM&#x6708;DD&#x65E5;&quot;);
</code></pre><p>2.&#x4EFB;&#x610F;&#x65F6;&#x95F4;&#x6233;&#x683C;&#x5F0F;&#x5316;&#xFF0C;&#x4EE5;YYYY-MM-DD HH:mm:ss&#x5F62;&#x5F0F;&#x663E;&#x793A;</p>
<pre><code> var t1=moment(1411641720000).format(&apos;YYYY-MM-DD HH:mm:ss&apos;);
</code></pre><h2 id="&#x83B7;&#x53D6;&#x524D;&#x4E00;&#x5929;&#x65E5;&#x671F;&#xFF0C;&#x683C;&#x5F0F;&#x4EE5;yyyy-mm-dd&#x5F62;&#x5F0F;&#x663E;&#x793A;">&#x83B7;&#x53D6;&#x524D;&#x4E00;&#x5929;&#x65E5;&#x671F;&#xFF0C;&#x683C;&#x5F0F;&#x4EE5;YYYY-MM-DD&#x5F62;&#x5F0F;&#x663E;&#x793A;</h2>
<pre><code>var t11=moment().day(0).format(&apos;YYYY-MM-DD&apos;);
</code></pre><h2 id="&#x83B7;&#x53D6;&#x672C;&#x5468;&#x4E94;&#x65E5;&#x671F;&#xFF0C;&#x683C;&#x5F0F;&#x4EE5;yyyy-mm-dd&#x5F62;&#x5F0F;&#x663E;&#x793A;">&#x83B7;&#x53D6;&#x672C;&#x5468;&#x4E94;&#x65E5;&#x671F;&#xFF0C;&#x683C;&#x5F0F;&#x4EE5;YYYY-MM-DD&#x5F62;&#x5F0F;&#x663E;&#x793A;</h2>
<pre><code>var t12=moment().weekday(5).format(&apos;YYYY-MM-DD&apos;);
</code></pre><h2 id="&#x83B7;&#x53D6;&#x4E0A;&#x5468;&#x4E94;&#x65E5;&#x671F;&#xFF0C;&#x683C;&#x5F0F;&#x4EE5;yyyy-mm-dd&#x5F62;&#x5F0F;&#x663E;&#x793A;">&#x83B7;&#x53D6;&#x4E0A;&#x5468;&#x4E94;&#x65E5;&#x671F;&#xFF0C;&#x683C;&#x5F0F;&#x4EE5;YYYY-MM-DD&#x5F62;&#x5F0F;&#x663E;&#x793A;</h2>
<pre><code>var t13=moment().weekday(-3).format(&apos;YYYY-MM-DD&apos;);
</code></pre><p>&#x53EF;&#x4EE5;&#x7B80;&#x5355;&#x7406;&#x89E3;&#x4E3A;&#x4E0A;&#x5468;&#x5012;&#x6570;&#x7B2C;&#x51E0;&#x5929;&#xFF0C;&#x4E0A;&#x5468;&#x5012;&#x6570;&#x7B2C;&#x4E09;&#x5929;&#x5C31;&#x662F;&#x4E0A;&#x5468;&#x4E94;&#x4E86;&#xFF0C;&#x548C;&#x5F53;&#x5929;&#x65E5;&#x671F;&#x65E0;&#x5173;</p>
<h2 id="&#x83B7;&#x53D6;&#x5F53;&#x524D;&#x5E74;&#x4EFD;&#x3001;&#x6708;&#x4EFD;&#x3001;&#x65E5;&#x671F;">&#x83B7;&#x53D6;&#x5F53;&#x524D;&#x5E74;&#x4EFD;&#x3001;&#x6708;&#x4EFD;&#x3001;&#x65E5;&#x671F;</h2>
<pre><code>var t14=moment().year()
var t15=moment().month()//&#x6B64;&#x5904;&#x6708;&#x4EFD;&#x4ECE;0&#x5F00;&#x59CB;&#xFF0C;&#x5F53;&#x524D;&#x6708;&#x8981;+1
var t16=moment().date();
</code></pre><p>&#x6CE8;&#x610F;&#x8FD9;&#x4E2A;&#x5730;&#x65B9;&#xFF0C;&#x65E5;&#x671F;&#x4E0D;&#x662F;.day()/days()</p>
<p>&#x7ED3;&#x5408;t14&#xFF0C;t15&#xFF0C;t16&#x5C31;&#x53EF;&#x4EE5;&#x8F93;&#x51FA;&#x4F60;&#x60F3;&#x8981;&#x7684;&#x4EFB;&#x4F55;&#x548C;&#x5F53;&#x524D;&#x65E5;&#x671F;&#x3001;&#x6708;&#x4EFD;&#x76F8;&#x5173;&#x7684;&#x65E5;&#x671F;
 &#x4F8B;&#x5982;&#xFF1A;&#x6211;&#x60F3;&#x83B7;&#x53D6;&#x53BB;&#x5E74;&#x4ECA;&#x5929;&#x7684;&#x5B8C;&#x6574;&#x65E5;&#x671F;&#xFF0C;&#x5982;&#xFF1A;&#x4ECA;&#x5929;&#x662F;2018-7-23&#xFF0C;&#x6211;&#x8981;&#x8F93;&#x51FA;&#x7684;&#x662F;2017-7-23</p>
<pre><code>console.log(`${t14-1}-${t15+1}-${t16}`)
</code></pre><p>&#x5F53;&#x7136;&#x8FD9;&#x4E0D;&#x662F;&#x83B7;&#x53D6;&#x53BB;&#x5E74;&#x4ECA;&#x5929;&#x65E5;&#x671F;&#x6700;&#x597D;&#x7684;&#x529E;&#x6CD5;&#xFF0C;&#x4F46;&#x4F60;&#x53EF;&#x4EE5;&#x62FC;&#x51FA;&#x5F88;&#x591A;&#x4F60;&#x60F3;&#x8981;&#x7684;&#x7EC4;&#x5408;&#xFF0C;&#x4E0B;&#x9762;&#x4F1A;&#x4ECB;&#x7ECD;&#x66F4;&#x597D;&#x7684;&#x83B7;&#x53D6;&#x53BB;&#x5E74;&#x4ECA;&#x65E5;&#x7684;&#x65B9;&#x6CD5;&#x3002;</p>
<h2 id="&#x83B7;&#x53D6;&#x4E0A;&#x4E2A;&#x6708;&#x4ECA;&#x5929;&#x7684;&#x65E5;&#x671F;&#xFF0C;&#x683C;&#x5F0F;&#x4EE5;yyyy-mm-dd&#x663E;&#x793A;">&#x83B7;&#x53D6;&#x4E0A;&#x4E2A;&#x6708;&#x4ECA;&#x5929;&#x7684;&#x65E5;&#x671F;&#xFF0C;&#x683C;&#x5F0F;&#x4EE5;YYYY-MM-DD&#x663E;&#x793A;</h2>
<pre><code>var t18=moment().subtract(1, &apos;months&apos;).format(&apos;YYYY-MM-DD&apos;);
</code></pre><h2 id="&#x83B7;&#x53D6;&#x4E0A;&#x4E2A;&#x6708;&#x65E5;&#x671F;&#xFF0C;&#x683C;&#x5F0F;&#x4EE5;yyyy-mm&#x663E;&#x793A;">&#x83B7;&#x53D6;&#x4E0A;&#x4E2A;&#x6708;&#x65E5;&#x671F;&#xFF0C;&#x683C;&#x5F0F;&#x4EE5;YYYY-MM&#x663E;&#x793A;</h2>
<pre><code>var t19=moment().subtract(1, &apos;months&apos;).format(&apos;YYYY-MM&apos;)
</code></pre><h2 id="&#x83B7;&#x53D6;&#x524D;&#x4E00;&#x5929;&#x65E5;&#x671F;&#xFF0C;&#x683C;&#x5F0F;&#x4EE5;yyyy-mm-dd&#x663E;&#x793A;">&#x83B7;&#x53D6;&#x524D;&#x4E00;&#x5929;&#x65E5;&#x671F;&#xFF0C;&#x683C;&#x5F0F;&#x4EE5;YYYY-MM-DD&#x663E;&#x793A;</h2>
<pre><code>var t20 = moment().subtract(1, &apos;days&apos;).format(&apos;YYYY-MM-DD&apos;);
</code></pre><h2 id="&#x83B7;&#x53D6;&#x53BB;&#x5E74;&#x4ECA;&#x5929;&#x7684;&#x65E5;&#x671F;&#xFF0C;&#x683C;&#x5F0F;&#x4EE5;yyyy-mm-dd&#x663E;&#x793A;&#xFF0C;&#x5373;&#x7B80;&#x4FBF;&#x7684;&#x83B7;&#x53D6;&#x53BB;&#x5E74;&#x4ECA;&#x5929;&#x65E5;&#x671F;&#x7684;&#x65B9;&#x6CD5;">&#x83B7;&#x53D6;&#x53BB;&#x5E74;&#x4ECA;&#x5929;&#x7684;&#x65E5;&#x671F;&#xFF0C;&#x683C;&#x5F0F;&#x4EE5;YYYY-MM-DD&#x663E;&#x793A;&#xFF0C;&#x5373;&#x7B80;&#x4FBF;&#x7684;&#x83B7;&#x53D6;&#x53BB;&#x5E74;&#x4ECA;&#x5929;&#x65E5;&#x671F;&#x7684;&#x65B9;&#x6CD5;</h2>
<pre><code>var t21= moment().subtract(1, &apos;year&apos;).format(&apos;YYYY-MM-DD&apos;);
</code></pre><h2 id="&#x83B7;&#x53D6;&#x4E24;&#x4E2A;&#x5C0F;&#x65F6;&#x4E4B;&#x540E;&#x7684;&#x65F6;&#x95F4;">&#x83B7;&#x53D6;&#x4E24;&#x4E2A;&#x5C0F;&#x65F6;&#x4E4B;&#x540E;&#x7684;&#x65F6;&#x95F4;</h2>
<pre><code>var t22=moment().add(2,&apos;hours&apos;).format(&apos;YYYY-MM-DD HH:mm:ss&apos;);
</code></pre><p>&#x8FD9;&#x4E2A;&#x7684;&#x5E94;&#x7528;&#x662F;&#x83B7;&#x53D6;&#x65F6;&#x95F4;&#x6233;&#x8FC7;&#x671F;&#x65F6;&#x95F4;
 &#x6BD4;&#x8F83;&#x4E5F;&#x5F88;&#x7B80;&#x5355;&#xFF0C;&#x53EA;&#x8981;&#x83B7;&#x53D6;&#x5F53;&#x524D;&#x65F6;&#x95F4;&#xFF0C;&#x4E00;&#x6837;&#x7684;format&#x7528;&gt;&lt;=&#x53F7;&#x6BD4;&#x8F83;&#x5C31;&#x53EF;&#x4EE5;&#x4E86;</p>
<h2 id="&#x83B7;&#x53D6;&#x4E94;&#x5929;&#x524D;&#x7684;&#x65E5;&#x671F;">&#x83B7;&#x53D6;&#x4E94;&#x5929;&#x524D;&#x7684;&#x65E5;&#x671F;</h2>
<p>&#x4F8B;&#x5982;:&#x4ECA;&#x5929;2018-7-23&#xFF0C;&#x83B7;&#x53D6;&#x5230;&#x7684;&#x65F6;&#x95F4;&#x662F;2018-7-18</p>
<pre><code>var t23=moment().subtract(5, &apos;days&apos;).format(&apos;YYYY-MM-DD&apos;);
</code></pre><p>&#x4F5C;&#x8005;&#xFF1A;xxt1ngt1ng</p>
<p>&#x94FE;&#x63A5;&#xFF1A;<a href="https://www.jianshu.com/p/e5b7c0606a3f" target="_blank">https://www.jianshu.com/p/e5b7c0606a3f</a></p>
<p>&#x6765;&#x6E90;&#xFF1A;&#x7B80;&#x4E66;</p>
<p>&#x7B80;&#x4E66;&#x8457;&#x4F5C;&#x6743;&#x5F52;&#x4F5C;&#x8005;&#x6240;&#x6709;&#xFF0C;&#x4EFB;&#x4F55;&#x5F62;&#x5F0F;&#x7684;&#x8F6C;&#x8F7D;&#x90FD;&#x8BF7;&#x8054;&#x7CFB;&#x4F5C;&#x8005;&#x83B7;&#x5F97;&#x6388;&#x6743;&#x5E76;&#x6CE8;&#x660E;&#x51FA;&#x5904;&#x3002;</p>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="less传参问题：在url中插入变量今天在需要用less给url传递参数时遇到了小问题，一番搜索后有了下述解决方法.html" class="navigation navigation-prev " aria-label="Previous page: less传参问题：在url中插入变量今天在需要用less给url传递参数时遇到了小问题，一番搜索后有了下述解决方法">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="node.JS中配置http-server.html" class="navigation navigation-next " aria-label="Next page: node.JS中配置http-server">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"moment 和date-fns","level":"1.18","depth":1,"next":{"title":"node.JS中配置http-server","level":"1.19","depth":1,"path":"project/node.JS中配置http-server.md","ref":"project/node.JS中配置http-server.md","articles":[]},"previous":{"title":"less传参问题：在url中插入变量今天在需要用less给url传递参数时遇到了小问题，一番搜索后有了下述解决方法","level":"1.17","depth":1,"path":"project/less传参问题：在url中插入变量今天在需要用less给url传递参数时遇到了小问题，一番搜索后有了下述解决方法.md","ref":"project/less传参问题：在url中插入变量今天在需要用less给url传递参数时遇到了小问题，一番搜索后有了下述解决方法.md","articles":[]},"dir":"ltr"},"config":{"gitbook":"*","theme":"default","variables":{},"plugins":[],"pluginsConfig":{"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"}},"file":{"path":"project/moment 和date-fns.md","mtime":"2019-06-19T12:37:19.237Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2019-07-18T03:07:23.077Z"},"basePath":"..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../gitbook/gitbook.js"></script>
    <script src="../gitbook/theme.js"></script>
    
        
        <script src="../gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

